home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
shazam11.zip
/
ED.INC
< prev
next >
Wrap
Text File
|
1991-11-04
|
7KB
|
163 lines
const
FileSpec : string = '*.TXT' ;
function ExecDialog ( P : PDialog ; Data : pointer ) : word ;
var
Result : word ;
begin
Result := cmCancel ;
P := PDialog ( Application^.ValidView ( P ) ) ;
if P <> NIL then
begin
if Data <> NIL then P^.SetData ( Data^ ) ;
Result := DeskTop^.ExecView ( P ) ;
if ( Result <> cmCancel ) and
( Data <> NIL ) then P^.GetData ( Data^ ) ;
Dispose ( P , Done ) ;
end ;
ExecDialog := Result ;
end ;
function CreateFindDialog : PDialog ;
var
D : PDialog ;
Control : PView ;
R : TRect ;
begin
R.Assign ( 0 , 0 , 38 , 12 ) ;
D := New ( PDialog , Init ( R , 'Find' ) ) ;
with D^ do
begin
Options := Options or ofCentered ;
R.Assign ( 3 , 3 , 32 , 4 ) ;
Control := New ( PInputLine , Init ( R , 80 ) ) ;
Insert ( Control ) ;
R.Assign ( 2 , 2 , 15 , 3 ) ;
Insert ( New ( PLabel , Init ( R , '~T~ext to find' , Control ) ) ) ;
R.Assign ( 32 , 3 , 35 , 4 ) ;
Insert ( New ( PHistory , Init ( R , PInputLine ( Control ) , 10 ) ) ) ;
R.Assign ( 3 , 5 , 35 , 7 ) ;
Insert ( New ( PCheckBoxes , Init ( R ,
NewSItem ( '~C~ase sensitive' ,
NewSItem ( '~W~hole words only' , NIL ) ) ) ) ) ;
R.Assign ( 14 , 9 , 24 , 11 ) ;
Insert ( New ( PButton , Init ( R , 'O~K~' , cmOk , bfDefault ) ) ) ;
Inc ( R.A.X , 12 ) ;
Inc ( R.B.X , 12 ) ;
Insert ( New ( PButton ,
Init ( R , 'Cancel' , cmCancel , bfNormal ) ) ) ;
SelectNext ( FALSE ) ;
end ;
CreateFindDialog := D ;
end ;
function CreateReplaceDialog : PDialog ;
var
D : PDialog ;
Control : PView ;
R : TRect ;
begin
R.Assign ( 0 , 0 , 40 , 16 ) ;
D := New ( PDialog , Init ( R , 'Replace' ) ) ;
with D^ do
begin
Options := Options or ofCentered ;
R.Assign ( 3 , 3 , 34 , 4 ) ;
Control := New ( PInputLine , Init ( R , 80 ) ) ;
Insert ( Control ) ;
R.Assign ( 2 , 2 , 15 , 3 ) ;
Insert ( New ( PLabel , Init ( R , '~T~ext to find' , Control ) ) ) ;
R.Assign ( 34 , 3 , 37 , 4 ) ;
Insert ( New ( PHistory , Init ( R , PInputLine ( Control ) , 10 ) ) ) ;
R.Assign ( 3 , 6 , 34 , 7 ) ;
Control := New ( PInputLine , Init ( R , 80 ) ) ;
Insert ( Control ) ;
R.Assign ( 2 , 5 , 12 , 6 ) ;
Insert ( New ( PLabel , Init ( R , '~N~ew text' , Control ) ) ) ;
R.Assign ( 34 , 6 , 37 , 7 ) ;
Insert ( New ( PHistory , Init ( R , PInputLine ( Control ) , 11 ) ) ) ;
R.Assign ( 3 , 8 , 37 , 12 ) ;
Insert ( New ( PCheckBoxes ,
Init ( R ,
NewSItem ( '~C~ase sensitive' ,
NewSItem ( '~W~hole words only' ,
NewSItem ( '~P~rompt on replace' ,
NewSItem ( '~R~eplace all' , NIL ) ) ) ) ) ) ) ;
R.Assign ( 17 , 13 , 27 , 15 ) ;
Insert ( New ( PButton , Init ( R , 'O~K~' , cmOk , bfDefault ) ) ) ;
R.Assign ( 28 , 13 , 38 , 15 ) ;
Insert ( New ( PButton , Init ( R , 'Cancel' , cmCancel , bfNormal ) ) ) ;
SelectNext ( FALSE ) ;
end ;
CreateReplaceDialog := D ;
end ;
function DoEditDialog ( Dialog : integer ; Info : pointer ) : word ; far ;
var
R : TRect ;
T : TPoint ;
begin
case Dialog of
edOutOfMemory :
DoEditDialog := MessageBox ( 'Not enough memory for this operation.' ,
NIL , mfError + mfOkButton ) ;
edReadError :
DoEditDialog := MessageBox ( 'Error reading file %s.' ,
@Info , mfError + mfOkButton ) ;
edWriteError :
DoEditDialog := MessageBox ( 'Error writing file %s.' ,
@Info , mfError + mfOkButton ) ;
edCreateError :
DoEditDialog := MessageBox ( 'Error creating file %s.' ,
@Info , mfError + mfOkButton ) ;
edSaveModify :
DoEditDialog := MessageBox ( '%s has been modified. Save?' ,
@Info , mfInformation + mfYesNoCancel ) ;
edSaveUntitled :
DoEditDialog := MessageBox ( 'Save untitled file?' ,
NIL , mfInformation + mfYesNoCancel ) ;
edSaveAs :
DoEditDialog := ExecDialog ( New ( PFileDialog , Init ( FileSpec ,
'Save file as' , '~N~ame' , fdOkButton , 101 ) ) , Info ) ;
edFind :
DoEditDialog := ExecDialog ( CreateFindDialog , Info ) ;
edSearchFailed :
DoEditDialog := MessageBox ( 'Search string not found.' ,
NIL , mfError + mfOkButton ) ;
edReplace :
DoEditDialog := ExecDialog ( CreateReplaceDialog , Info ) ;
edReplacePrompt :
begin
{- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Avoid placing the dialog on the same line as the cursor
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -}
R.Assign ( 0 , 1 , 40 , 8 ) ;
R.Move ( ( Desktop^.Size.X - R.B.X ) div 2 , 0 ) ;
Desktop^.MakeGlobal ( R.B , T ) ;
Inc ( T.Y ) ;
if TPoint ( Info ).Y <= T.Y then
R.Move ( 0 , Desktop^.Size.Y - R.B.Y - 2 ) ;
DoEditDialog := MessageBoxRect ( R , 'Replace this occurence?' ,
NIL , mfYesNoCancel + mfInformation ) ;
end ;
end ;
end ;
function OpenEditor ( FileName : FNameStr ; Visible : boolean ) : PEditWindow ;
var
P : PView ;
R : TRect ;
begin
DeskTop^.GetExtent ( R ) ;
P := Application^.ValidView (
New ( PEditWindow ,
Init ( R , FileName, wnNoNumber ) ) ) ;
if not Visible then P^.Hide ;
DeskTop^.Insert ( P ) ;
OpenEditor := PEditWindow ( P ) ;
end ;